import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xingsu/util/image_util.dart';

class SearchWidget extends StatelessWidget {
  final VoidCallback? clickCallback;
  final String placeholder;
  final TextEditingController controller;
  final ValueChanged<String> onSubmitted;
  final FocusNode? focusNode;

  SearchWidget(
      {required this.placeholder,
      required this.controller,
      required this.onSubmitted,
      this.clickCallback,
      this.focusNode});

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: clickCallback,
      child: Container(
        alignment: Alignment.centerLeft,
        child: Row(
          children: [
            Expanded(
                child: Container(
              height: 40,
              alignment: Alignment.centerLeft,
              padding: const EdgeInsets.symmetric(horizontal: 10),
              decoration: BoxDecoration(
                  color: Get.theme.backgroundColor,
                  borderRadius: BorderRadius.circular(5)),
              child: Row(children: [
                loadAssetImage("icon_search", width: 16),
                const SizedBox(
                  width: 2,
                ),
                Expanded(
                    child: TextField(
                  enabled: clickCallback == null,
                  textInputAction: TextInputAction.search,
                  controller: controller,
                  focusNode: focusNode,
                  onSubmitted: onSubmitted,
                  style: const TextStyle(fontSize: 13),
                  decoration: InputDecoration(
                      contentPadding: EdgeInsets.zero,
                      border:
                          const OutlineInputBorder(borderSide: BorderSide.none),
                      hintText: placeholder,
                      hintStyle: const TextStyle(color: Color(0xFF696974))),
                ))
              ]),
            )),
          ],
        ),
      ),
    );
  }
}
